package com.cai.servlet.common.topic;

import com.cai.dao.DetailedTopicDao;
import com.cai.dao.impl.DetailedTopicDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author RuoLi
 */
@WebServlet(name = "ServletDetailedTopicInfoInsert", value = "/common/detailedTopicInsert")
public class ServletDetailedTopicInsert extends HttpServlet {
    DetailedTopicDao detailedTopicDao = new DetailedTopicDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        Map<String, String[]> map = req.getParameterMap();
        int status = detailedTopicDao.insertDetailedTopicData(map);
        if (status==1){
            //获取两个id
            resp.getWriter().write(detailedTopicDao.getAfterInsertTopicId());
        }else {
            resp.getWriter().write(-1);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
